﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../../common/jsp/taglibs.jsp"%>
<!-- 
    Copyright (C)  2011  chen wei hua.
    Permission is granted to copy, distribute and/or modify this document
    under the terms of the GNU Free Documentation License, Version 2.0
    or any later version published by the Free Software Foundation;
    with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
    A copy of the license is included in the section entitled "GNU Free Documentation License".
 -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>仓库整理</TITLE>
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<%@ include file="../../common/jsp/config.jsp"%>
<%@ include file="../../common/jsp/validate.jsp"%>
<script type="text/javascript" src="common/js/calendar/WdatePicker.js" ></script>
<script type="text/javascript">

$(document).ready(function() {
	$("#saveOrderPrepareOutStroe").validate();
});

function checkValue(id) {
	var batchValue = parseFloat($("#batchNumbers-" + id).html());
	var inputValue = parseFloat($("#outStroeNumbers-" + id).val());
	if (batchValue < inputValue) {
		alert("发货数量不能大于批次数量");
	}
}

function saveSubmit() {
	if ($("td[id^='batchNumbers-']").length == 0) {
		alert("没有出货数量，无法保存");
		return false;
	}
	var allIsCurrent = true;
	$("td[id^='batchNumbers-']").each(function(i){
		var id = this.id;
		var inputId = id.replace("batchNumbers-", "outStroeNumbers-");
		var batchValue = parseFloat($(this).html());
		var inputValue = parseFloat($("#" + inputId).val());
		if (batchValue < inputValue) {
			allIsCurrent = false;
		}
	});

	if (!allIsCurrent) {
		alert("发货数量不能大于批次数量");
		return false;
	}
	
	$("td[id^='numbers-']").each(function(i){
		var orderNumber = parseFloat($(this).html());
		var totleOutNumber = 0;
		var id = this.id.replace("numbers-", "");
		var inputId = "outStroeNumbers-" + id;
		$("input[id^='" + inputId + "']").each(function(i){
			totleOutNumber += parseFloat($(this).val());
		});
		if (orderNumber != totleOutNumber) {
			allIsCurrent = false;
		}
	});

	if (allIsCurrent) {
		$("#saveOrderPrepareOutStroe").submit();
	} else if (window.confirm('发货数量和订单数量不相符，确定要保存吗?')==true) {
		$("#saveOrderPrepareOutStroe").submit();
	}
	return false;
}
</script>
</HEAD>
<BODY>
    <div class="subnav" align="left">
           <table width="100%" border="0" cellspacing="0" cellpadding="0">
		  <tr>
			<td width="100%" align="left" height="31">&nbsp;<img src="common/images/title-pk.gif" border="0"  align="absmiddle"/>&nbsp;<span class="subnavtxt1">出货管理</span>
			&nbsp;<img src="common/images/leftico2.gif" border="0"  align="absmiddle"/>&nbsp;<span class="subnavtxt2">仓库整理</span></td>
		  </tr>
		</table>
      </div>
	 <s:actionerror cssStyle="color:red"/>
     <s:form action="saveOrderPrepareOutStroe">
     <s:hidden name="orderId" value="%{order.id}" />
     <div class="main_1">
       <table width="99%" border="0" cellpadding="10" cellspacing="1" bgcolor="#D3DEEF">
         <tr>
           <td align="left" class="Blue14" bgcolor="#FAFAFA" colspan="4">出货单信息</td>
         </tr>
         <tr>
		    <td width="20%" bgcolor="#FAFAFA" align="right"><strong>创建日期</strong></td>
		    <td width="30%" bgcolor="#FAFAFA"><s:date name="order.createDate" format="yyyy-MM-dd"/></td>
		    <td width="20%" bgcolor="#FAFAFA" align="right"><strong>客户名称</strong></td>
	        <td width="30%" bgcolor="#FAFAFA"><s:property value="order.customName"/></td>
		 </tr>
		<tr>
	      <td bgcolor="#FAFAFA" align="right"><strong>订单号</strong></td>
	      <td bgcolor="#FAFAFA"><s:property value="order.contractNo"/></td>
	      <td bgcolor="#FAFAFA" align="right"><strong>预出货日期</strong></td>
	      <td bgcolor="#FAFAFA"><s:date name="order.expectOutDate" format="yyyy-MM-dd"/></td>
		</tr>
		<tr>
	      <td bgcolor="#FAFAFA" align="right"><strong>出货日期</strong></td>
	      <td bgcolor="#FAFAFA"><s:date name="order.outDate" format="yyyy-MM-dd"/></td>
	      	      <td bgcolor="#FAFAFA" align="right"><strong>运输方式</strong></td>
	      <td bgcolor="#FAFAFA"><s:property value="order.logisticsType"/></td>
		</tr>
		<tr>
	      <td bgcolor="#FAFAFA" align="right"><strong>到达时间</strong></td>
	      <td bgcolor="#FAFAFA"><s:property value="order.arriveDate"/></td>
	      <td bgcolor="#FAFAFA" align="right"></td>
	      <td bgcolor="#FAFAFA"></td>
		</tr>
      </table>
     </div>
     <div class="clear"></div>
	 <div class="main_scroll">
       <table width="1010px" cellpadding="0" cellspacing="1" border="0" class="ksglxx2a">
        <tr class="ksglxx2bg">
          <th width="50px" >大分类</th>
          <th width="60px" >中分类</th>
          <th width="95px" >名称</th>
          <th width="180px" >型号</th>
          <th width="180px" >其他</th>
		  <th width="50px">单位</th>
		  <th width="65px">订单数量</th>
		  <th width="95px">包装数量(箱)</th>
		  <th width="95px">库存批次</th>
		  <th width="65px">批次数量</th>
		  <th width="75px">出货数量</th>
		</tr>
		<s:iterator value="order.orderDetails" id="detail" status="st">
            <s:if test="#st.Odd">
              <tr class="odd">
            </s:if>
            <s:else>
              <tr class="even">
            </s:else>
		  <s:if test="#detail.batchInfos.size==0">
              <td><s:property value="#detail.productRootCategory" /></td>
              <td><s:property value="#detail.productCategory" /></td>
              <td><s:property value="#detail.productName" /></td>
              <td><s:property value="#detail.productType" /></td>
              <td><s:property value="#detail.productSku" /></td>
              <td><s:property value="#detail.unit" /></td>
    		  <td><s:property value="#detail.number" /></td>
              <td><s:property value="#detail.packageNumber" /></td>
              <td>&nbsp;</td>
           	  <td>0</td>
           	  <td>0</td>
		  </s:if>
		  <s:else>
          <s:iterator value="#detail.batchInfos" id="batchInfo" status="bt">
            <s:if test="#bt.index==0">
              <td rowspan='<s:property value="#detail.batchInfos.size" />'><s:property value="#detail.productRootCategory" /></td>
              <td rowspan='<s:property value="#detail.batchInfos.size" />'><s:property value="#detail.productCategory" /></td>
              <td rowspan='<s:property value="#detail.batchInfos.size" />'><s:property value="#detail.productName" /></td>
              <td rowspan='<s:property value="#detail.batchInfos.size" />'><s:property value="#detail.productType" /></td>
              <td rowspan='<s:property value="#detail.batchInfos.size" />'><s:property value="#detail.productSku" /></td>
              <td rowspan='<s:property value="#detail.batchInfos.size" />'><s:property value="#detail.unit" /></td>
    		  <td rowspan='<s:property value="#detail.batchInfos.size" />' id='numbers-<s:property value="#st.index" />'><s:property value="#detail.number" /></td>
              <td rowspan='<s:property value="#detail.batchInfos.size" />'><s:property value="#detail.packageNumber" /></td>
              <td><s:property value="#batchInfo.batchNo" /></td>
           	  <td id='batchNumbers-<s:property value="#st.index" />-<s:property value="#bt.index" />'>
           	      <s:property value="#batchInfo.number" /></td>
           	  <td>
           	    <s:textfield id="outStroeNumbers-%{#st.index}-%{#bt.index}" name="outStroeNumbers" size="5" 
           	    			 cssClass="{required:true,maxlength:10,number:true}" value="%{#batchInfo.outNumber}" onblur="checkValue('%{#st.index}-%{#bt.index}')"/>
           	    <s:hidden name="detailIds" value="%{#detail.id}" />
           	    <s:hidden name="productIds" value="%{#detail.productId}" />
           	    <s:hidden name="outStroeBatchNos" value="%{#batchInfo.batchNo}" />
           	  </td>
            </s:if>
            <s:else>
             <s:if test="#st.Odd">
              <tr class="odd">
             </s:if>
             <s:else>
              <tr class="even">
             </s:else>
              <td><s:property value="#batchInfo.batchNo" /></td>
           	  <td id='batchNumbers-<s:property value="#st.index" />-<s:property value="#bt.index" />'>
           	      <s:property value="#batchInfo.number" /></td>
           	  <td>
           	    <s:textfield id="outStroeNumbers-%{#st.index}-%{#bt.index}" name="outStroeNumbers" size="5" 
           	    			 cssClass="{required:true,maxlength:10,number:true}" value="%{#batchInfo.outNumber}" onblur="checkValue('%{#st.index}-%{#bt.index}')"/>
           	    <s:hidden name="detailIds" value="%{#detail.id}" />
           	    <s:hidden name="productIds" value="%{#detail.productId}" />
           	    <s:hidden name="outStroeBatchNos" value="%{#batchInfo.batchNo}" />
           	  </td>
           	  </tr>
            </s:else>
          </s:iterator>
          </s:else>
          </tr>
	    </s:iterator>
       </table>
      </div>
     <div class="clear"></div>
	 <div class="main_1">
		<table width="98%" border="0" cellpadding="5" cellspacing="0" class="gr-text1">
		   <tr>
			 <td width="50%" align="right"><input name="button" type="button" class="input1" value="保存" onclick="saveSubmit()"/></td>
			 <td width="50%" align="left"><input type="button" value="关闭" class="input1" onclick='javascript:window.location.href="prepareOutStroeList.action"' /></td>
		   </tr>
	   </table>
	</div>
	</s:form>
	<div class="clear"></div>
</BODY></HTML>
